package com.tedu;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f=new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");

        Channel c=f.newConnection().createChannel();
        c.queueDeclare("task_queue", false, false, false, null);

        DeliverCallback deliverCallback=new DeliverCallback() {
            @Override
            public void handle(String s, Delivery delivery) throws IOException {
                byte[] body=delivery.getBody();
                String msg=new String(body);
                System.out.println("收到："+msg);
            }
        };

        CancelCallback cancelCallback=new CancelCallback() {
            @Override
            public void handle(String s) throws IOException {

            }
        };
        /*
        * @Param
        * 1.队列
        * 2.ack 模式
        * 3.处理消息回调
        * 取消处理消息回调*/

        c.basicConsume("task_queue", true,deliverCallback,cancelCallback);
        c.close();

    }
}
